/**
 * @author 徐梦轲
 * @data 2022/5/26 0026 - 11:44
 */

import java.util.Stack;

/**
 *
 * @author     ：徐梦轲
 * @date       ：2022/5/26 0026 11:44
 */

public class Solution {
    public boolean IsPopOrder(int [] pushA,int [] popA) {
        Stack<Integer> stack = new Stack<>();
        int j = 0;
        for (int i = 0; i < pushA.length; i++) {
            stack.push(pushA[i]);
            while (!stack.isEmpty() && j < popA.length && stack.peek() == popA[j]) {
                stack.pop();
                j++;
            }
        }
        return stack.isEmpty();
    }
}
